package mvc;

import java.awt.KeyEventDispatcher;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * 
 * Register key events, and pass any data to the Controller.
 * 
 * @author Dylan Swiggett
 *
 */
public class KeyListener extends KeyAdapter implements KeyEventDispatcher{
	Controller controller;
	
	public KeyListener(Controller controller){
		super();
		
		this.controller = controller;
	}
	
	public void keyPressed(KeyEvent evt){
		controller.keyPressed(evt);
	}
	
	public void keyReleased(KeyEvent evt){
		controller.keyReleased(evt);
	}
	
	public void keyTyped(KeyEvent evt){
		controller.keyTyped(evt);
	}

	/*
	 * A Dispatcher will capture all key events, regardless of the focus.
	 * 
	 * (non-Javadoc)
	 * @see java.awt.KeyEventDispatcher#dispatchKeyEvent(java.awt.event.KeyEvent)
	 */
	public boolean dispatchKeyEvent(KeyEvent evt) {	
		switch (evt.getID()){
		case KeyEvent.KEY_PRESSED:
			keyPressed(evt);
			break;
		case KeyEvent.KEY_RELEASED:
			keyReleased(evt);
			break;
		case KeyEvent.KEY_TYPED:
			keyTyped(evt);
			break;
		default:
			return false;
		}
		return true;
	}
}
